# coding:utf-8
import os
from configparser import ConfigParser

import pytesseract
from PIL import Image

user_pswd_cfg = os.environ['user_pswd']
cp = ConfigParser()
cp.read(user_pswd_cfg, encoding='utf-8')
tesseract_cmd = cp.get('path', 'tesseract')
base_dir = './ext/Hello/'


class HelloDemo:
    def _test_run(self):
        """
        hd = HelloDemo()
        hd._test_run()
        """
        pytesseract.pytesseract.tesseract_cmd = tesseract_cmd
        files = os.listdir(base_dir)
        print(files)
        for item in files:
            file_name = base_dir + item
            print(file_name)
            if os.path.isfile(file_name):
                im = Image.open(file_name)
                data = pytesseract.image_to_string(im)
                print(data)


if __name__ == '__main__':
    hd = HelloDemo()
    hd._test_run()
